<template>
  <div class="common-page">
    <div class="table-box">
      <el-table
        v-loading="loading"
        height="100%"

        :data="tableData"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(255, 255, 255, 0.8)"
        @selection-change="onSelect"
      >

        <el-table-column v-for="item in columns" :key="item.prop" :prop="item.prop" :label="item.label" align="center" />
      </el-table>
    </div>
    <div class="page-box">
      <el-pagination
        background
        :current-page="pageNo"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalSize"
        @size-change="changePageSize"
        @current-change="changePageNo"
      />
    </div>
  </div>
</template>

<script>
import crud from '@/mixins/crud'
import { http } from '@/api'
import {getName, MeetingType} from "@/dict";

export default {
  name: 'Index',
  mixins: [crud],
  props: {
    userId: String
  },
  data() {
    return {
      request: {
        page: http.professor.commentList
      },
      columns: [
        { prop: 'projectName', label: '项目名称' },
        { prop: 'meetingTypeName', label: '会议类型' },
        { prop: 'departName', label: '组织单位' },
        { prop: 'assess', label: '评审意见' }
      ],
      tableData: [

      ]
    }
  },
  methods: {
    formatTableData(data) {
      data.forEach(el => {
        el.meetingTypeName = getName(el.meetingType, MeetingType)
      })
    },
    initData() {
      if (!this.userId) return
      if (!this.request || this.loading) return
      if (this.request.page) {
        this.loading = true
        this.request.page(this.getQueryParams()).then(res => {
          try {
            res = res.data
            this.loading = false
            this.totalSize = res.total
            const tableData = res.records
            this.formatTableData(tableData)
            this.tableData = tableData
          } catch (e) {
            console.log(e)
          }
        }).catch(() => this.loading = false)
      } else if (this.request.list || this.request.tree) {
        this.loading = true
        this.request.list(this.getQueryParams2()).then(res => {
          this.loading = false
          const tableData = res.data
          this.totalSize = res.data.length
          if (this.formatTableData) {
            this.formatTableData(tableData)
          }
          this.tableData = tableData
        }).catch(() => this.loading = false)
      }
    },
    getQueryParams() {
      const params = {
        pageNo: this.pageNo,
        pageSize: this.pageSize
      }
      return {
        ...params,
        id: this.userId
      }
    }
  }
}
</script>

<style scoped lang="scss">
</style>
